package com.hd.assistant.dal.dataobject.ordermining;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.citrus.util.StringUtil;
import com.hd.util.CommonUtil;

public class ItemCost implements Serializable{
	public static Integer HAS_COST = 1;
	public static Integer NOT_HAS_COST = 0;
	
	public static Integer HAS_SKU_COST = 1;
	public static Integer NOT_HAS_SKU_COST = 0;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Long id;
	private String itemId;
	private Long userId;
	private String userCats;
	private String sjbm;
	private String title;
	private String itemPic;
	private Double price;
	private Double cost;
	/**
	 * 如果需要设置sku成本 则存储在这个字段 存储的格式是  skuid:display:cost;
	 */
	private String skuCosts;
	private Integer hasSkuCosts ;
	private Integer hasCost ;
	private Date costModifyTime;
	private Date gmtCreate;
	private Date gmtModify;
	private String status;
	private Map<String, SkuCost> skuCost = new HashMap<String, SkuCost>();
	
	
	private Long totalTrades;
	private Long totalSaleNum;
	private Double totalSales;
	private Double totalProfits;
	
	
	private Long num;
	
	
	public Long getNum() {
		return num;
	}
	public void setNum(Long num) {
		this.num = num;
	}
	public Long getTotalTrades() {
		return totalTrades;
	}
	public void setTotalTrades(Long totalTrades) {
		this.totalTrades = totalTrades;
	}
	public Long getTotalSaleNum() {
		return totalSaleNum;
	}
	public void setTotalSaleNum(Long totalSaleNum) {
		this.totalSaleNum = totalSaleNum;
	}
	public Double getTotalSales() {
		return totalSales;
	}
	public void setTotalSales(Double totalSales) {
		this.totalSales = totalSales;
	}
	public Double getTotalProfits() {
		return totalProfits;
	}
	public void setTotalProfits(Double totalProfits) {
		this.totalProfits = totalProfits;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Map<String, SkuCost> getSkuCost() {
		return skuCost;
	}
	public void setSkuCost(Map<String, SkuCost> skuCost) {
		this.skuCost = skuCost;
	}
	public ItemCost() {
		skuCost = new java.util.HashMap<String, SkuCost>();
	}
	public String getItemId() {
		return itemId;
	}
	public void setItemId(String itemId) {
		this.itemId = itemId;
	}
	public Long getUserId() {
		return userId;
	}
	public void setUserId(Long userId) {
		this.userId = userId;
	}
	public String getUserCats() {
		return userCats;
	}
	public void setUserCats(String userCats) {
		this.userCats = userCats;
	}
	public String getSjbm() {
		return sjbm;
	}
	public void setSjbm(String sjbm) {
		this.sjbm = sjbm;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getItemPic() {
		return itemPic;
	}
	public void setItemPic(String itemPic) {
		this.itemPic = itemPic;
	}
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	public Double getCost() {
		return cost;
	}
	public void setCost(Double cost) {
		this.cost = cost;
	}
	public String getSkuCosts() {
		return skuCosts;
	}
	public void setSkuCosts(String skuCosts) {
		this.skuCosts = skuCosts;
		if(!StringUtil.isEmpty(skuCosts)){
			if(skuCost == null)
				skuCost = new HashMap<String, SkuCost>();
			String ss[] = StringUtil.split(skuCosts, ";");
			for(String sku:ss){
				if(!StringUtil.isBlank(sku)){
					String []details = StringUtil.split(sku, ":");
					if(details != null && (details.length == 4)){
						String skuId = details[0];
						String skuName = details[1];
						double price = CommonUtil.parseDouble(details[2]);
						double cost = CommonUtil.parseDouble(details[3]);
						SkuCost skuC = new SkuCost(skuId,skuName,price,cost);
						this.skuCost.put(skuId, skuC);
					}
				}
			}
		}
	}
	public void generateSkusFromMap(){
		if(skuCost==null ||skuCost.size() == 0){
			return;
		}
		StringBuffer sb = new StringBuffer();
		for(Map.Entry<String, SkuCost> entry: skuCost.entrySet()){
			SkuCost sku = entry.getValue();
			sb.append(sku.getSkuId()).append(":").append(sku.getDisplay()).append(":").append(sku.getPrice()).append(":").append(sku.getCost()).append(";");
		}
		this.skuCosts = sb.toString();
	}
	public Integer getHasSkuCosts() {
		return hasSkuCosts;
	}
	public void setHasSkuCosts(Integer hasSkuCosts) {
		this.hasSkuCosts = hasSkuCosts;
	}
	public Date getCostModifyTime() {
		return costModifyTime;
	}
	public void setCostModifyTime(Date costModifyTime) {
		this.costModifyTime = costModifyTime;
	}
	public Date getGmtCreate() {
		return gmtCreate;
	}
	public void setGmtCreate(Date gmtCreate) {
		this.gmtCreate = gmtCreate;
	}
	public Date getGmtModify() {
		return gmtModify;
	}
	public void setGmtModify(Date gmtModify) {
		this.gmtModify = gmtModify;
	}
	public boolean hasSkuCosts(){
		return hasSkuCosts != null && this.hasSkuCosts.equals(HAS_SKU_COST);
	}
	public void setHasSkuCosts(boolean need){
		this.hasSkuCosts = need?HAS_SKU_COST:NOT_HAS_SKU_COST;
	}
	public Integer getHasCost() {
		return hasCost;
	}
	public void setHasCost(Integer hasCost) {
		this.hasCost = hasCost;
	}
	public boolean hasCostInfo(){
		return hasCost != null && hasCost.equals(HAS_COST);
	}
	public double getCostDisplay(){
		if(this.cost != null)
			return this.cost;
		else
			return 0.00;
	}
	public String getNumCostDisplay(){
		DecimalFormat df = new DecimalFormat("0.00");
		if(this.cost != null && this.num != null)
			return df.format(this.cost*this.num);
		else
			return "0.00";
	}
	public String getProfitDisplay(){
		DecimalFormat df = new DecimalFormat("0.00");
		return df.format(this.price - this.getCostDisplay());
	}
}
